﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Power.Model;
using System.Data;
using System.Data.SqlClient;

namespace Power.DAL
{
    public class ReportDAL
    {
        public ReportM[] ListToFind(string sttext)
        {
            DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Report where Device= @Temppar ", new SqlParameter("@Temppar", sttext));
            ReportM[] Reports = new ReportM[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Reports[i] = ToReportM(dt.Rows[i]);
            }
            return Reports;
        }



        public void InsertReport(ReportM op)
        {
            //bit类型，在sql语句中要写0、1
            //在.net中要用bool表示
            SqlHelper.ExecuteNonQuery(@"insert into T_Report(
                Device,Theme,BoText,Fee) values(@Device,@Theme,@BoText,@Fee)",
                    new SqlParameter("@Device", op.Device),
                    new SqlParameter("@Theme", op.Theme),
                    new SqlParameter("@BoText", op.BoText),
                    new SqlParameter("@Fee", op.Fee));
        }








        private ReportM ToReportM(DataRow row)
        {
            ReportM op = new ReportM();
            op.Id = (long)row["Id"];
            op.Device = (string)row["Device"];
            op.Fee = (string)row["Fee"];
            op.Theme = (string)row["Theme"];

            op.BoText = (string)row["BoText"];

            return op;
        }

    }
}
